/*
	Copyright (c) 2004-2009, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.widget.DataPresentation"]){
dojo._hasResource["dojox.widget.DataPresentation"]=true;
dojo.provide("dojox.widget.DataPresentation");
dojo.experimental("dojox.widget.DataPresentation");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.charting.Chart2D");
dojo.require("dojox.charting.widget.Legend");
dojo.require("dojox.charting.action2d.Tooltip");
dojo.require("dojox.charting.action2d.Highlight");
dojo.require("dojo.colors");
dojo.require("dojo.data.ItemFileWriteStore");
(function(){
var _1={"default":["#497c91","#59a0bd","#9dc7d9","#c7e0e9","#7b78a4","#8d88c7","#ada9d6","#c9c6e4","#768b4e","#677e13","#a8c179","#c0d0a0","#b7b35c","#e8e667","#eeea99","#f0eebb","#b39c53","#e9c756","#ebcf81","#efdeb0","#956649","#b17044","#c28b69","#cfb09b","#815454","#a05a5a","#c99999","#ddc0c0","#868686","#a5a5a5","#bebebe","#d8d8d8"],"alternative-1":["#497c91","#ada9d6","#768b4e","#eeea99","#b39c53","#c28b69","#815454","#bebebe","#59a0bd","#c9c6e4","#677e13","#f0eebb","#e9c756","#cfb09b","#a05a5a","#d8d8d8","#9dc7d9","#7b78a4","#a8c179","#b7b35c","#ebcf81","#956649","#c99999","#868686","#c7e0e9","#8d88c7","#c0d0a0","#e8e667","#efdeb0","#b17044","#ddc0c0","#a5a5a5"],"alternative-2":["#497c91","#59a0bd","#dc7d90","#c7e0e9","#7b78a4","#8d88c7","#ada9d6","#c9c6e4","#768b4e","#677e13","#a8c179","#c0d0a0","#b7b35c","#e8e667","#eeea99","#f0eebb","#b39c53","#e9c756","#ebcf81","#efdeb0","#956649","#b17044","#c28b69","#cfb09b","#815454","#a05a5a","#c99999","#ddc0c0","#868686","#a5a5a5","#bebebe","#d8d8d8"]};
var _2={"default":["#22627d","#1a80a8","#71b2cb","#a6cedd","#5e5996","#6d66b9","#8a84c5","#b1add8","#5b6b1f","#85a54a","#88aa47","#a2bb6b","#918e38","#c8c548","#d4cf76","#dddb9d","#947b30","#cfab39","#cdb360","#d2c086","#74482e","#8c4f29","#a96e47","#b7927a","#572828","#7f3333","#ab6d6d","#cca0a0","#535353","#7f7f7f","#a2a2a2","#c7c7c7"],"alternative-1":["#22627d","#8a84c5","#5b6b1f","#d4cf76","#947b30","#a96e47","#572828","#a2a2a2","#1a80a8","#b1add8","#85a54a","#dddb9d","#cfab39","#b7927a","#7f3333","#c7c7c7","#71b2cb","#5e5996","#88aa47","#918e38","#cdb360","#74482e","#ab6d6d","#535353","#a6cedd","#6d66b9","#a2bb6b","#c8c548","#d2c086","#8c4f29","#cca0a0","#7f7f7f"],"alternative-2":["#22627d","#1a80a8","#71b2cb","#a6cedd","#5e5996","#6d66b9","#8a84c5","#b1add8","#5b6b1f","#85a54a","#88aa47","#a2bb6b","#918e38","#c8c548","#d4cf76","#dddb9d","#947b30","#cfab39","#cdb360","#d2c086","#74482e","#8c4f29","#a96e47","#b7927a","#572828","#7f3333","#ab6d6d","#cca0a0","#535353","#7f7f7f","#a2a2a2","#c7c7c7"]};
var _3=function(_4,_5,_6,_7,_8,_9,_a,_b,_c){
var _d=_5;
if(!_d){
_4.innerHTML="";
_d=new dojox.charting.Chart2D(_4);
}
var _e=[],_f=_8;
_e[0]={value:0,text:""};
var _10=_a.series_data[0].slice(0);
if(_7){
_10.reverse();
}
var _11=_10.length;
switch(_6.toLowerCase()){
case "hybrid":
case "clusteredcolumns":
case "areas":
case "stackedcolumns":
case "stackedareas":
case "lines":
var _12=_4.offsetWidth;
var tmp=_10[0].length*_10.length*7;
if(_f==1){
for(var z=1;z<500;++z){
if((tmp/z)<_12){
break;
}
++_f;
}
}
break;
}
for(var i=0;i<_11;i++){
if(i%_f==0){
_e.push({value:(i+1),text:_10[i]});
}else{
_e.push({value:(i+1),text:""});
}
}
_e.push({value:(_11+1),text:""});
_d.addPlot("misc",{type:"Lines",markers:true,shadows:{dx:2,dy:2,dw:2}});
var _13=0;
var _14=10000000;
tnum=0;
var _15=_a.series_name.length;
for(var i=0;i<_15;i++){
if(_a.series_chart[i]&&(_a.series_data[i].length>0)){
var _16=[];
var _17=_a.series_data[i].length;
for(var j=0;j<_17;j++){
var val=_a.series_data[i][j];
_16.push(val);
if(val>_13){
_13=val;
}
if(val<_14){
_14=val;
}
++tnum;
}
var _18=_a.series_name[i];
if(_7){
_16.reverse();
}
if(_6=="hybrid"&&(_a.series_charttype[i]=="line")){
_d.addSeries(_18,_16,{plot:"misc",stroke:{color:_2[_9][i]},fill:_1[_9][i]});
}else{
_d.addSeries(_18,_16,{stroke:{color:_2[_9][i]},fill:_1[_9][i]});
}
}
}
var mts=10;
if(_13>50000){
mts=10000;
}else{
if(_13>5000){
mts=1000;
}else{
if(_13>500){
mts=100;
}else{
if(_13>100){
mts=20;
}
}
}
}
switch(_6.toLowerCase()){
case "hybrid":
case "clusteredcolumns":
_d.addAxis("y",{vertical:true,fixLower:"major",fixUpper:"major",natural:true,min:0});
_d.addAxis("x",{vertical:false,labels:_e,min:0,max:_10.length+1,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"ClusteredColumns",gap:4});
break;
case "clusteredbars":
_d.addAxis("x",{fixLower:"major",fixUpper:"major",natural:true,min:0});
_d.addAxis("y",{vertical:true,labels:_e,min:0,max:_10.length+1,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"ClusteredBars",gap:4});
break;
case "areas":
_d.addAxis("y",{vertical:true,fixLower:"major",fixUpper:"major",max:_13,min:_14,majorTickStep:mts});
_d.addAxis("x",{vertical:false,labels:_e,min:1,max:_10.length,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"Areas",lines:true,areas:true,markers:false});
break;
case "stackedcolumns":
_d.addAxis("y",{vertical:true,fixLower:"major",fixUpper:"major"});
_d.addAxis("x",{vertical:false,labels:_e,min:0,max:_10.length+1,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"StackedColumns",gap:4});
break;
case "stackedbars":
_d.addAxis("x",{fixLower:"major",fixUpper:"major",natural:true,min:0});
_d.addAxis("y",{vertical:true,labels:_e,min:0,max:_10.length+1,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"StackedBars",gap:4});
break;
case "stackedareas":
_d.addAxis("y",{vertical:true,fixLower:"major",fixUpper:"major"});
_d.addAxis("x",{vertical:false,labels:_e,min:1,max:_10.length,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"StackedAreas",lines:true,areas:true,markers:false});
break;
case "lines":
_d.addAxis("y",{vertical:true,fixLower:"major",fixUpper:"major",max:_13,min:_14,majorTickStep:mts});
_d.addAxis("x",{vertical:false,labels:_e,min:1,max:_10.length,majorTickStep:1,minorTickStep:1});
_d.addPlot("default",{type:"Lines",markers:true});
break;
}
var _19=new dojox.charting.action2d.Tooltip(_d,"misc");
var _1a=new dojox.charting.action2d.Tooltip(_d,"default");
var hl=new dojox.charting.action2d.Highlight(_d,"default");
_d.render();
return _d;
};
var _1b=function(_1c,_1d,_1e,_1f){
var _20=_1d;
if(!_20){
if(_1f){
_20=new dojox.charting.widget.Legend({chart:_1e,horizontal:false},_1c);
}else{
_20=new dojox.charting.widget.Legend({chart:_1e,vertical:false},_1c);
}
}
return _20;
};
var _21=function(_22,_23,_24,_25,_26){
var _27=_23||new dojox.grid.DataGrid({},_22);
_27.startup();
_27.setStore(_24,_25,_26);
var _28=[];
for(var ser=0;ser<_24.series_name.length;ser++){
if(_24.series_grid[ser]&&(_24.series_data[ser].length>0)){
_28.push({field:"data."+ser,name:_24.series_name[ser],width:"auto",formatter:_24.series_gridformatter[ser]});
}
}
_27.setStructure(_28);
_27.render();
return _27;
};
var _29=function(_2a,_2b){
if(_2b.title){
_2a.innerHTML=_2b.title;
}
};
var _2c=function(_2d,_2e){
if(_2e.footer){
_2d.innerHTML=_2e.footer;
}
};
var _2f=function(_30,_31){
var _32=_30;
if(_31){
var _33=_31.split(/[.\[\]]+/);
for(var _34 in _33){
if(_32){
_32=_32[_33[_34]];
}
}
}
return _32;
};
dojo.declare("dojox.widget.DataPresentation",null,{type:"chart",chartType:"clusteredBars",reverse:false,labelMod:1,legendVertical:false,scheme:"default",constructor:function(_35,_36){
dojo.mixin(this,_36);
this.domNode=dojo.byId(_35);
this[this.type+"Node"]=this.domNode;
this.chartNode=dojo.byId(this.chartNode);
this.legendNode=dojo.byId(this.legendNode);
this.gridNode=dojo.byId(this.gridNode);
this.titleNode=dojo.byId(this.titleNode);
this.footerNode=dojo.byId(this.footerNode);
if(this.url){
this.setURL(null,this.refresh);
}else{
if(this.data){
this.setData(null,this.refresh);
}else{
this.setStore();
}
}
},setURL:function(url,_37){
if(_37&&this.refreshInterval){
clearInterval(this.refreshInterval);
this.refreshInterval=undefined;
}
this.url=url||this.url;
this.refresh=_37||this.refresh;
var me=this;
dojo.xhrGet({url:this.url,handleAs:"json",load:function(_38,_39){
me.setData(_38);
},error:function(xhr,_3a){
log("oops");
}});
if(_37&&(this.refresh>0)){
this.refreshInterval=setInterval(function(){
me.setURL();
},this.refresh);
}
},setData:function(_3b,_3c){
if(_3c&&this.refreshInterval){
clearInterval(this.refreshInterval);
this.refreshInterval=undefined;
}
this.data=_3b||this.data;
this.refresh=_3c||this.refresh;
var _3d=(typeof this.series=="function")?this.series(this.data):this.series;
var _3e=[];
var _3f=[];
var _40=[];
var _41=[];
var _42=[];
var _43=[];
var _44=[];
var _45=0;
for(var ser=0;ser<_3d.length;ser++){
_3e[ser]=_2f(this.data,_3d[ser].datapoints);
if(_3e[ser]&&(_3e[ser].length>_45)){
_45=_3e[ser].length;
}
_3f[ser]=[];
_40[ser]=_3d[ser].name||(_3d[ser].namefield?_2f(this.data,_3d[ser].namefield):null)||("series "+ser);
_41[ser]=(_3d[ser].chart!==false);
_42[ser]=_3d[ser].charttype||"bar";
_43[ser]=(_3d[ser].grid!==false);
_44[ser]=_3d[ser].gridformatter;
}
var _46,_47,_48,_49;
var _4a=[];
for(_46=0;_46<_45;_46++){
_47={index:_46};
for(ser=0;ser<_3d.length;ser++){
if(_3e[ser]&&(_3e[ser].length>_46)){
_48=_2f(_3e[ser][_46],_3d[ser].field);
_49=parseFloat(_48);
if(!isNaN(_49)){
_48=_49;
}
_47["data."+ser]=_48;
_3f[ser].push(_48);
}
}
_4a.push(_47);
}
if(_45<=0){
_4a.push({index:0});
}
var _4b=new dojo.data.ItemFileWriteStore({data:{identifier:"index",items:_4a}});
if(this.data.title){
_4b.title=this.data.title;
}
if(this.data.footer){
_4b.footer=this.data.footer;
}
_4b.series_data=_3f;
_4b.series_name=_40;
_4b.series_chart=_41;
_4b.series_charttype=_42;
_4b.series_grid=_43;
_4b.series_gridformatter=_44;
this.setPreparedStore(_4b);
if(_3c&&(this.refresh>0)){
var me=this;
this.refreshInterval=setInterval(function(){
me.setData();
},this.refresh);
}
},setStore:function(_4c,_4d,_4e){
this.setPreparedStore(_4c,_4d,_4e);
},setPreparedStore:function(_4f,_50,_51){
this.preparedstore=_4f||this.store;
this.query=_50||this.query;
this.queryOptions=_51||this.queryOptions;
if(this.preparedstore){
if(this.chartNode){
this.chartWidget=_3(this.chartNode,this.chartWidget,this.chartType,this.reverse,this.labelMod,this.scheme,this.preparedstore,this.query,this,_51);
}
if(this.legendNode){
this.legendWidget=_1b(this.legendNode,this.legendWidget,this.chartWidget,this.legendVertical);
}
if(this.gridNode){
this.gridWidget=_21(this.gridNode,this.gridWidget,this.preparedstore,this.query,this.queryOptions);
}
if(this.titleNode){
_29(this.titleNode,this.preparedstore);
}
if(this.footerNode){
_2c(this.footerNode,this.preparedstore);
}
}
},getChartWidget:function(){
return this.chartWidget;
},getGridWidget:function(){
return this.gridWidget;
}});
})();
}
